home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CD-ROM Today - The Disc! 5
/
CD-ROM Today - The Disc (Issue 5)(November 1994).ISO
/
mac
/
Mac shareware
/
Education
/
RLaB
/
rlib
/
complement.r
< prev
next >
Wrap
Text File
|
1994-09-21
|
780b
|
36 lines
//-------------------------------------------------------------------//
// complement
// Syntax: complement ( A , B )
// Description:
// The complement function returns a vector-set that contains the
// complement of A in B. In plain English: the elements of B that are
// not in A.
// See Also: intersection, set, union
//-------------------------------------------------------------------//
complement = function ( A, B )
{
local (Comp, a, i)
if (A.n == 0) { return [B]; }
if (min (size (A)) != 1) {
error ("complement: 1st arg must be a vector");
}
if (min (size (B)) != 1) {
error ("complement: 2st arg must be a vector");
}
a = set (A); Comp = set (B);
for (i in 1:a.n)
{
Comp = Comp[ find (a[i] != Comp) ];
}
return Comp
};